﻿using MediatR;
using ProductionLine.API.Application.Command.PlanDetail.Read;
using ProductionLine.Domain.Plan;
using ProductionLine.ErrorCode;
using ProductionLine.Infrastructure.Interface;

namespace ProductionLine.API.Application.Handler.PlanDetail.Read
{
    public class GetOnePlanHandler : IRequestHandler<GetOnePlanCommand, APIResult<PlanModel>>
    {
        IBaseRepository<PlanModel> planRepo;

        public GetOnePlanHandler(IBaseRepository<PlanModel> planRepo)
        {
            this.planRepo = planRepo;
        }
        public Task<APIResult<PlanModel>> Handle(GetOnePlanCommand request, CancellationToken cancellationToken)
        {
            APIResult<PlanModel> res=new APIResult<PlanModel>();
            var searchId= planRepo.GetAll().Where(c => !c.IsDel && c.PlanId==request.PlanId).FirstOrDefault();
            if (searchId == null)
            {
                res.Code=APIEnum.Fail;
                res.Msg = "不存在";
                return Task.FromResult(res);
            }
            res.Msg = "查询计划详情基础信息成功";
            res.Code=APIEnum.Success;
            res.Data = searchId;
            return Task.FromResult(res);
        }
    }
}
